package cn.edu.zafu.bigdata.zqt.readFromFile;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

public class main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文件地址：");
        String fileName = scanner.nextLine();
        System.out.println("请输入要写入的内容：");
        String content = scanner.nextLine();
        writeToFile(fileName, content);
        readFromFile(fileName);
    }

    public static void readFromFile(String fileName) {
        try {
            String content = new String(Files.readAllBytes(Paths.get(fileName)));
            System.out.println("文件内容为：");
            System.out.println(content);
        }
        catch (IOException e) {
            System.err.println("读取文件失败！"+e.getMessage());
        }
    }

    public static void writeToFile(String fileName, String content) {
        try {
            Files.write(Paths.get(fileName), content.getBytes());
            System.out.println("文件内容写入成功！");
        }
        catch (IOException e) {
            System.err.println("写入文件失败！"+e.getMessage());
        }
    }
}